package com.hy.xstream.converter;

import java.util.HashSet;

import org.hy.domain.User;
import org.hy.domain.group.GMember;

import com.thoughtworks.xstream.converters.Converter;
import com.thoughtworks.xstream.converters.MarshallingContext;
import com.thoughtworks.xstream.converters.UnmarshallingContext;
import com.thoughtworks.xstream.io.HierarchicalStreamReader;
import com.thoughtworks.xstream.io.HierarchicalStreamWriter;

public class PosterConverter implements Converter{

	private HashSet<Class> enabledClazz = new HashSet<Class>();
	
	protected Class currentClazz;
	
	public PosterConverter() {
		enabledClazz.add(User.class);
		enabledClazz.add(GMember.class);
	}
	
	public void marshal(Object value, HierarchicalStreamWriter writer,
			MarshallingContext context) {
		// TODO Auto-generated method stub
		writer.startNode("publisher");
		context.convertAnother(value);
		writer.endNode();
		System.out.println("marshall...:"+value);
	}

	
	public Object unmarshal(HierarchicalStreamReader reader,
			UnmarshallingContext context) {
		System.out.println("unmarshall class...:"+currentClazz);
		return null;
	}

	
	public boolean canConvert(Class clazz) {
		currentClazz = clazz;
		return enabledClazz.contains(clazz);
	}

	
}
